<?php
namespace Apipad\Controller;

use Think\Controller;

//仓库
class UserKuerpWarehouseLogController extends UserWarehouseController
{

    function _before_lists(){
        $request = I('');
    }

    //编辑
    function edit(){
		$name = CONTROLLER_NAME;
		$model = D($name);
        $id = $_REQUEST [$model->getPk()];
        $vo = $model->find($id);
        if(!$vo){
            $this->ajaxErrReturn('日志不存在'); 
        }
        $wdata['id'] = I('id');
        if(I('pur_detail_id')){
            /*
            $pd_model = M('PurchaseDetail');
            $pd_wdata['id'] = I('pur_detail_id');
            $pd_vo = $pd_model->where($pd_wdata)->find();
            if($pd_vo){
                $sdata['pur_id'] = $pd_vo['plan_id'];
                $sdata['pur_detail_id'] = I('pur_detail_id');
            }
            */
        }
        $sdata['resource_type'] = I('resource_type');
        $sdata['remark'] = I('remark');
        $res = $model->where($wdata)->save($sdata);
        if(!$res){
            $this->ajaxErrReturn('修改失败');
        }
        $this->ajaxSucReturn('修改完成');

    }


    //回滚(库存返回)
    function revert(){
        $kwl_model = D('UserKuerpWarehouseLog');
        $kwl_model->startTrans();//启用事务
        $wdata['id'] = I('id');
        $kwl_vo = $kwl_model->lock(true)->where($wdata)->find();
        if(!$kwl_vo){
            $this->ajaxErrReturn('日志不存在'); 
        }
        if($kwl_vo['is_back']==1){
            $this->ajaxErrReturn('已驳回日志,无法再驳回'); 
        }
        $result = $kwl_model->revert($kwl_vo);
        if($result['status']){
            $sdata['is_fq'] = 1;
            $res = $kwl_model->where($wdata)->save($sdata);
            if(!$res){
                $this->ajaxErrReturn('更新出错'); 
            }
            $kwl_model->commit();
            $this->ajaxSucReturn('驳回成功'); 
        }else{
            $this->ajaxErrReturn($result['msg']); 
        }
    }

    
}

?>